package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.WeighbridgeMapper;
import com.ruoyi.lvlian.domain.Weighbridge;
import com.ruoyi.lvlian.service.IWeighbridgeService;

/**
 * 磅秤Service业务层处理
 *
 * @author lvlian
 * @date 2025-04-22
 */
@Service
public class WeighbridgeServiceImpl implements IWeighbridgeService {
    @Autowired
    private WeighbridgeMapper weighbridgeMapper;

    /**
     * 查询磅秤
     *
     * @param id 磅秤主键
     * @return 磅秤
     */
    @Override
    public Weighbridge selectWeighbridgeById(String id) {
        return weighbridgeMapper.selectWeighbridgeById(id);
    }

    /**
     * 查询磅秤列表
     *
     * @param weighbridge 磅秤
     * @return 磅秤
     */
    @Override
    public List<Weighbridge> selectWeighbridgeList(Weighbridge weighbridge) {
        return weighbridgeMapper.selectWeighbridgeList(weighbridge);
    }

    /**
     * 新增磅秤
     *
     * @param weighbridge 磅秤
     * @return 结果
     */
    @Override
    public int insertWeighbridge(Weighbridge weighbridge) {
        weighbridge.setId(MD5Utils.md5(weighbridge.getName() ));
        weighbridge.setCreateUser(SecurityUtils.getUsername());
        weighbridge.setCreateDate(DateUtils.getCurrentTime());
        return weighbridgeMapper.insertWeighbridge(weighbridge);
    }

    /**
     * 修改磅秤
     *
     * @param weighbridge 磅秤
     * @return 结果
     */
    @Override
    public int updateWeighbridge(Weighbridge weighbridge) {
        int updateResult =  weighbridgeMapper.updateWeighbridge(weighbridge);
        if (0 == updateResult) {
            updateResult = insertWeighbridge(weighbridge);
        }

        return updateResult;


    }

    /**
     * 批量删除磅秤
     *
     * @param ids 需要删除的磅秤主键
     * @return 结果
     */
    @Override
    public int deleteWeighbridgeByIds(String[] ids) {
        return weighbridgeMapper.deleteWeighbridgeByIds(ids);
    }

    /**
     * 删除磅秤信息
     *
     * @param id 磅秤主键
     * @return 结果
     */
    @Override
    public int deleteWeighbridgeById(String id) {
        return weighbridgeMapper.deleteWeighbridgeById(id);
    }
}
